﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iLangl.Model;
using iLangl.BusinessModel.Managers;
using iLangl.Transport.Communication;

namespace iLangl.BusinessModel.Actions.Push
{
	public class SyncedDataAction : BaseTPAction
	{
		private SyncedOneWayData result = null;
		public SyncedDataAction()
			: base()
		{
			ResponseContext = new SyncedDataResponseContext();
			RequestContext = new ActionResultRequestContext();

		}

		protected override void _execute()
		{
			result = (SyncedOneWayData)ResponseContext.GetContext();


			if (result == null)
			{
				throw new ApplicationException("Synced Data Is Empty!");
			}

			PluginLicense license = PluginManager.Instance.GetLicense(PluginLiceneKey);

			if (license == null)
			{
				throw new ApplicationException(string.Format("Plugin License Key='{0}' is invalid!", PluginLiceneKey));
			}

			result.Subscriber = license.ID;

			SynchronizationManager.Instance.SyncData(result);

			ActionResult actionresult = new ActionResult();
			RequestContext.SetContext(actionresult);
		}

		protected override string GetName()
		{
			return "SyncedDataAction";
		}
	}
}
